package com.web.dao;

import com.web.controller.web.WebFeedBackController;
import com.web.entity.Feedback;

import static org.apache.ibatis.jdbc.SqlBuilder.*;

/**
 * @author FDjavaone
 */
public class FeedbackSqlProvider {


    public String insertSelective(Feedback record) {
        BEGIN();
        INSERT_INTO("t_feedback");

        if (record.getmId() != null) {
            VALUES("m_id", "#{mId,jdbcType=BIGINT}");
        }

        if (record.getContent() != null) {
            VALUES("content", "#{content,jdbcType=VARCHAR}");
        }

        if (record.getCreateTime() != null) {
            VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            VALUES("modify_time", "#{modifyTime,jdbcType=TIMESTAMP}");
        }

        return SQL();
    }


    public String updateByPrimaryKeySelective(Feedback record) {
        BEGIN();
        UPDATE("t_feedback");

        if (record.getmId() != null) {
            SET("m_id = #{mId,jdbcType=BIGINT}");
        }

        if (record.getContent() != null) {
            SET("content = #{content,jdbcType=VARCHAR}");
        }

        if (record.getCreateTime() != null) {
            SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
        }

        if (record.getModifyTime() != null) {
            SET("modify_time = #{modifyTime,jdbcType=TIMESTAMP}");
        }

        WHERE("id = #{id,jdbcType=BIGINT}");

        return SQL();
    }


    public String selectAllFeedbacks(WebFeedBackController.FeedbackColumns record) {
        BEGIN();
        SELECT("tf.*");
        SELECT("tm.name");
        SELECT("tm.phone");
        FROM("t_feedback tf ");
        LEFT_OUTER_JOIN(" t_member tm on tf.m_id=tm.id ");
        ORDER_BY("create_time desc");

        return SQL();
    }

}